Hello and welcome back to the costs.
So at the end of the last session we created our first list.
So what is the list.
A list is another object or data type that stores multiple other objects.
So for example a list can store objects of different data types like integer US floats drinks and so
on.
So let's stop creating our first or second list.
So we are opening and square brackets and.
Yeah.
We are storing for entered into just one two three far separated by a comma.
And then let's see what happens if you're on the cell.
So it returns back to a list with four elements.
One two three four.
And if you check the type of El then we get back on that list.
And as I said before we can store elements of different data types.
So for example here we had the US now and our next list M we store three float elements.
So let's execute here the cell and we can see here we have a list m with one point five two point four
and three point seven.
And also we can create a list with String objects.
So for example list n uh we have a dock or we have a card and we have a mouse and we can have a list
where we have different data types.
So for example list o contains an integer one that contains a flow two point far and contains the string
object dark and it's no problem at works.
And you can think of a list like a backpack.
So for example if you go hiking you put into your bag a bottle of water sandwich two T-shirts and maybe
a football and a yard.
Everything fits into your bag and that's the same as with the list so you can actually put everything
into a list and store it there and we saw on the last session that we can transform a string into a
list.
So for example we have the string.
This is a string and we can transform it by calling the function list and we get back a list with all
single elements of the string.
So T H I.
Also an empty space.
And also here at the exclamation mark so let's check again what data type we have here follower list
P and of course it's a list and we can also count the amount of elements in the list.
So in this case it's 17.
And yeah we can have we can count here.
And um yeah as we had before also the empty spaces and the exclamation marks also a string and also
count four for the length.
So next we can take the arithmetic sum of all elements.
So we take the sum of l let's check L is on the list with four integers so a sum of four integers should
should work.
So the sum of one two three four four is ten and you can also take the sum of list m s so getting again
m here is the list that's floating floats.
So this should also work.
So it's seven point six.
And we tried to take the sum of lists and so list n and list and contains strings.
So the sum of strings.
I'm not sure if this works
no it doesn't work so it gives less than Iran.
So let's get back to lists L in list l there are four integers one two three four.
And um what we can do with S and method Bill and method for lists called append and there we can append
another element to the end of the list.
So if we append five let's see what happens.
So then we get back a list with a five in the end.
And if you repeat this process and call a pen one more time with them the element five.
So we get another five.
And.
There's also a method that counts the number of occurrences of one element.
So if you want to count the number of occurrences of element five we can do so by calling the method
count that we have to.
So we have two times um the element five and now we can also remove an element from a list by calling
the method remove and in brackets we have the element we want to remove.
And so we have fear.
We want to remove five and we have two times five on our list and the method remove removes the first
occurrence of an element.
Let's check.
Okay.
So now we have only only if the five only ones and we can account again the five and s so we have one
time we have five on our list and we can also reverse the sequence of our elements by calling the method
reverse.
So let's do this.
And now you can see so before our the sequence of our lists was one two three four five and now we are
half and the reverse sequence five four three two one and that's also a method called Sarge where we
can start our list.
So in the case where we have only integers in our list Python automatically thoughts from from low to
high.
So let's see what happens
and there's also the possibility to reverse the order with the method thought.
So that's apparently the called reverse and it's uh by default it's set to fall.
But we can set it to true and now we affirm the reverse order and we can sort it again
to the ascending order.
So beginning with one.
All right.
And what we can also do we can add a list and a list so we have a list containing one two three four
five.
And we can add another list containing three integers six seven and eight.
So now we have a combined or a concatenated list.
One two three four five six seven eight.
So we have eight elements.
No one list.
And what is not working actually so we cannot subtract two.
Two lists.
So that s guess less an error message.
All right so let's go back to our initial list.
So we have a list with five elements and let's try to multiply our list.
Um with two and let's see what we get.
So actually Python here it concatenate many copies.
So in this case two copies and um yeah.
As you can see this is not an element y's multiplication.
So if you see at the times two you could also expect that uh one is uh multiplied by two two is multiplied
by two.
So that in the end we get two four six eight ten.
But this is not the case so this is not our how lists work.
So we just get many copies of the same lists here and uh for the sake of completeness um division of
uh lists.
An into us.
Uh not possible.
All right.
So that's uh that's it for.
For the time being and uh hope to see you again and lists parts 2 or so C in the next session by.